/*
 * 项目名称:    wms-server-jeecg
 * 创建人员:    FanZhiwen
 * 创建时间:    2023-11-20
 */
package org.jeecg.modules.flow.callback.inbound.order;

import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.business.outbound.entity.WmsOutReceiptTask;
import org.jeecg.modules.business.outbound.service.IWmsOutReceiptTaskService;
import org.jeecg.modules.business.third.service.IMesStatusService;
import org.jeecg.modules.business.warehouse.entity.WmsInReceiptTask;
import org.jeecg.modules.business.warehouse.service.IWmsInReceiptTaskService;
import org.jeecg.modules.flow.sys.common.BaseCustomBeanRun;
import org.jeecg.modules.flow.sys.entity.dto.BaseFlowDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 通知MES任务开始
 *
 * @author FanZhiwen
 * @version 1.0.0
 * @since 2023-11-20
 */
@Component
@Slf4j
@Deprecated
public class SendEndSuccessBean<T> extends BaseCustomBeanRun<T> {
    @Autowired
    private IWmsInReceiptTaskService iWmsInReceiptTaskService;
    @Autowired
    private IWmsOutReceiptTaskService wmsOutReceiptTaskService;
    @Autowired
    private IMesStatusService iMesStatusService;
    @Override
    public void actureRun() {
        BaseFlowDto baseFlowDto = this.getBaseFlowDto();
        String taskId = baseFlowDto.getInfoId();
        WmsInReceiptTask inTask = iWmsInReceiptTaskService.getById(taskId);
        WmsOutReceiptTask outTask = wmsOutReceiptTaskService.getById(taskId);
        boolean result = false;
        try {
            if (ObjectUtil.isNotNull(inTask)){
                result = iMesStatusService.warehouse(inTask.getId(),null,2,inTask);
            }
            if (ObjectUtil.isNotNull(outTask)){
                result = iMesStatusService.outbound(outTask.getId(),null,2,outTask);
            }
        }catch (Exception e){
            log.error("通知MES出现异常",e);
            baseFlowDto.setNextFailed(true);
            baseFlowDto.setResult(Result.error("通知MES执行失败: "+e.getMessage()));
        }
        if (!result){
            baseFlowDto.setNextFailed(true);
            baseFlowDto.setResult(Result.error("通知MES执行失败"));
        }
    }
}
